﻿Public Class OfficerManagementOld
    Inherits System.Web.UI.Page

    Public Shared Function ConvertStatus(ByVal status As String) As String
        Return Common.Utility.ConvertStatus(status)
    End Function

    Public Shared Function ConvertType(ByVal status As String) As String
        Return Common.Utility.ConvertType(status)
    End Function

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
        Dim strFrom As String = String.Empty
        Dim strTo As String = String.Empty

        If Not String.IsNullOrEmpty(Me.ccFrom.value) Then
            Dim dteFrom As New DateTime(Me.ccFrom.Year, Me.ccFrom.Month, Me.ccFrom.Day)
            strFrom = Common.UtilityDateTime.ConvertDateToString(dteFrom)
        End If

        If Not String.IsNullOrEmpty(Me.ccTo.value) Then
            Dim dteTo As New DateTime(Me.ccTo.Year, Me.ccTo.Month, Me.ccTo.Day)
            strTo = Common.UtilityDateTime.ConvertDateToString(dteTo)
        End If
        Me.Session(GlobalApp.sessionName) = BL.Officer.LoadOfficer(Me.txtNameTh.Text, Me.txtNameEn.Text, strFrom, strTo, Me.txtAppId.Text, Me.txtAppTel.Text, Me.txtCardNo.Text)
        BindGrid(0)
    End Sub

    Public Sub BindGrid(ByVal pageIndex As Integer)
        Me.gvList.PageIndex = pageIndex
        Me.gvList.DataSource = Me.Session(GlobalApp.sessionName)
        Me.gvList.DataBind()
    End Sub

    Protected Sub gvList_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvList.PageIndexChanging
        BindGrid(e.NewPageIndex)
    End Sub

    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnReset.Click
        Me.txtNameEn.Text = String.Empty
        Me.txtNameTh.Text = String.Empty
        Me.ccFrom.value = String.Empty
        Me.ccTo.value = String.Empty
    End Sub

    Protected Sub gvList_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles gvList.SelectedIndexChanged

        Try
            GlobalApp.DataSourceEditOfficer = BL.Officer.LoadProfile(Me.gvList.SelectedValue)
        Catch ex As Exception
            Me.Master.Alert("ไม่สามารถดึงข้อมูลที่ท่านต้องการได้")
            Common.LogError.AddLogException(ex)
        End Try

        Dim officer As Entity.OfficerInfoItem = GlobalApp.DataSourceEditOfficer
        If officer.officer_type.Equals("O") Then
            Response.Redirect("~/EditStaff.aspx", False)
        Else
            Response.Redirect("~/EditApplication.aspx", False)
        End If

    End Sub

    Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAdd.Click
        Me.Response.Redirect("~/registerstaff.aspx", False)
    End Sub
End Class